namespace IAM.Interface.Model
{
    using IAM.Interface.Common;
    using IAM.Interface.Model.Interface;
    using System;
    using System.Reflection;
    using System.Text;

    public class Dimension : AbstractConvertObject, IConvertXml
    {
        private IAM.Interface.Model.ACItems _acitems = null;
        private IAM.Interface.Model.ACSection _acsection = null;
        private IAM.Interface.Model.DimensionLevels _dimensionlevels = null;
        private string _display = "";
        private bool _hierachical = false;
        private string _id = "";
        private bool _multicheck = true;

        public override object ConvertToObject()
        {
            this.ID = EnDeCoding.Decode(this.CurrentXmlNode.Attributes["ID"].InnerText);
            this.Display = EnDeCoding.Decode(this.CurrentXmlNode.Attributes["Display"].InnerText);
            if (this.CurrentXmlNode.Attributes["Hierachical"].InnerText.ToLower() == "false")
            {
                this.Hierachical = false;
            }
            else
            {
                this.Hierachical = true;
            }
            if (this.CurrentXmlNode.Attributes["MultiCheck"].InnerText.ToLower() == "false")
            {
                this.MultiCheck = false;
            }
            else
            {
                this.MultiCheck = true;
            }
            this.ACSection = new IAM.Interface.Model.ACSection();
            this.ACSection.ID = EnDeCoding.Decode(this.CurrentXmlNode.Attributes["ACSection"].InnerText);
            this.DimensionLevels = new IAM.Interface.Model.DimensionLevels();
            this.DimensionLevels.CurrentXmlNode = this.CurrentXmlNode.SelectSingleNode("DimensionLevels");
            this.DimensionLevels = (IAM.Interface.Model.DimensionLevels) this.DimensionLevels.ConvertToObject();
            this.ACItems = new IAM.Interface.Model.ACItems(this);
            this.ACItems.CurrentXmlNode = this.CurrentXmlNode.SelectSingleNode("ACItems");
            this.ACItems = (IAM.Interface.Model.ACItems) this.ACItems.ConvertToObject();
            return this;
        }

        public override bool Equals(object obj)
        {
            Dimension dimension = null;
            try
            {
                dimension = (Dimension) obj;
            }
            catch
            {
                return false;
            }
            bool result = true;
            if (this.ID != dimension.ID)
            {
                result = false;
            }
            else
            {
                if (this.Display != dimension.Display)
                {
                    return false;
                }
                if (this.Hierachical != dimension.Hierachical)
                {
                    return false;
                }
                if (this.MultiCheck != dimension.MultiCheck)
                {
                    return false;
                }
                if (this.ACSection.ID != dimension.ACSection.ID)
                {
                    return false;
                }
                if (!this.DimensionLevels.Equals(dimension.DimensionLevels))
                {
                    result = false;
                }
                else if (!this.ACItems.Equals(dimension.ACItems))
                {
                    result = false;
                }
            }
            return result;
        }

        public override int GetHashCode()
        {
            int result = 1;
            PropertyInfo[] pi = base.GetType().GetProperties();
            foreach (PropertyInfo onofpi in pi)
            {
                result += onofpi.GetHashCode();
            }
            return result;
        }

        public IAM.Interface.Model.ACItems ACItems
        {
            get
            {
                return this._acitems;
            }
            set
            {
                this._acitems = value;
            }
        }

        public IAM.Interface.Model.ACSection ACSection
        {
            get
            {
                return this._acsection;
            }
            set
            {
                this._acsection = value;
            }
        }

        public IAM.Interface.Model.DimensionLevels DimensionLevels
        {
            get
            {
                return this._dimensionlevels;
            }
            set
            {
                this._dimensionlevels = value;
            }
        }

        public string Display
        {
            get
            {
                return this._display;
            }
            set
            {
                this._display = value;
            }
        }

        public bool Hierachical
        {
            get
            {
                return this._hierachical;
            }
            set
            {
                this._hierachical = value;
            }
        }

        public string ID
        {
            get
            {
                return this._id;
            }
            set
            {
                this._id = value;
            }
        }

        public bool MultiCheck
        {
            get
            {
                return this._multicheck;
            }
            set
            {
                this._multicheck = value;
            }
        }

        public string XML
        {
            get
            {
                return (this.XMLBoday + this.XMLFinis);
            }
        }

        public string XMLBoday
        {
            get
            {
                StringBuilder _xml = new StringBuilder();
                _xml.Append("<Dimension");
                _xml.Append(" ID=\"" + EnDeCoding.Encode(this.ID) + "\"");
                _xml.Append(" Display=\"" + EnDeCoding.Encode(this.Display) + "\"");
                _xml.Append(" Hierachical=\"" + this.Hierachical.ToString().ToLower() + "\"");
                _xml.Append(" MultiCheck=\"" + this.MultiCheck.ToString().ToLower() + "\"");
                _xml.Append(" ACSection=\"" + EnDeCoding.Encode(this.ACSection.ID) + "\"");
                _xml.Append(" >");
                _xml.Append(this.DimensionLevels.XML);
                _xml.Append(this.ACItems.XML);
                return _xml.ToString();
            }
        }

        public string XMLFinis
        {
            get
            {
                return "</Dimension>";
            }
        }
    }
}
